package com.mk.web;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.mk.web.service.AirplaneService;
import com.mk.web.service.impl.AirplaneServiceImpl;
import com.mk.web.service.impl.DemoServiceImpl;

/**
 * Created by WangChen on 2018/11/29 23:24.
 */
public class SpringMain4Aop {

    public static void main(String [] args){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext-aop.xml");

//        String[] names = applicationContext.getBeanDefinitionNames();
//        for (String name : names){
//            System.out.println(name);
//        }
        /**
         * 注意
         * 由于spring AOP 底层默认使用JDK动态代理实现
         * 所以如果切点实现了某接口，这里须写接口，不能写具体实现类
         * 否则会报类型转换异常
         * 而，如果切类没有实现接口，则不会
         */
//        AirplaneService airplaneService = (AirplaneService) applicationContext.getBean("airplane"/*, AirplaneServiceImpl.class*/);
//        airplaneService.fly();

        DemoServiceImpl demoService = applicationContext.getBean("demoService", DemoServiceImpl.class);
        demoService.demo();
    }
}
